<template>
  <el-container class="home_container">
    <el-header class="head_box">
      <div class="head_left"><img src="@/assets/youzi.png" alt="logo" /><span>电商后台管理系统</span></div>
      <div class="head_right"><el-button type="info" @click="logout">退出</el-button></div>
    </el-header>
    <el-container>
      <el-aside :width="isTrue ? '64px' : '200px'">
        <!-- 侧边栏菜单 -->
        <div class="toggle-btn" @click="togglebtn">|||</div>
        <el-menu background-color="rgb(78, 196, 243)" :unique-opened="true" :collapse="isTrue" :collapse-transition="false" text-color="#fff" active-text-color="#ffd04b" router :default-active="$router.currentRoute.path">
          <el-submenu :index="item.id + ''" v-for="item in meunList" :key="item.id">
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{ item.authName }}</span>
            </template>

            <!-- 二级菜单 -->
            <el-menu-item :index="'/' + subItem.path" v-for="subItem in item.children" :key="subItem.id">
              <i class="el-icon-menu"></i>
              <span>{{ subItem.authName }}</span>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

      <!-- 主体区域 -->
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      meunList: [],
      iconsObj: {
        '125': 'iconfont icon-users',
        '103': 'iconfont icon-tijikongjian',
        '101': 'iconfont icon-shangpin',
        '102': 'iconfont icon-danju',
        '145': 'iconfont icon-baobiao'
      },
      isTrue: false
    }
  },
  created() {
    this.getAsideList()
  },
  methods: {
    logout() {
      window.sessionStorage.clear()

      this.$router.push('/login')
    },
    async getAsideList() {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) return this.$message.eroor(res.meta.msg)
      this.meunList = res.data
    },
    togglebtn() {
      this.isTrue = !this.isTrue
      console.log(this.$router)
    }
  }
}
</script>

<style lang="less" scoped>
.home_container {
  height: 100%;
}
.el-header {
  background-color: rgb(91, 195, 236);
}
.el-aside {
  background-color: rgb(78, 196, 243);
  > .el-menu {
    border-right: none;
  }
}
.el-main {
  background-color: rgba(233, 231, 231, 0.53);
}
.el-button {
  background-color: skyblue;
}
.head_box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
  font-size: 20px;
  > .head_left {
    display: flex;
    align-items: center;
    > span {
      margin-left: 15px;
    }
    img {
      min-width: 50px;
      max-width: 80px;
    }
  }
}
.iconfont {
  margin-right: 10px;
}
.toggle-btn {
  background-color: rgb(93, 199, 241);
  color: #fff;
  text-align: center;
  line-height: 20px;
  letter-spacing: 0.2em;
  cursor: pointer;
}
</style>
